package demo00;

/**
 * 方式二：
 * implements Runnable 方式创建线程类
 * 优点是：不占用单继承名额；方便多个线程共享同一个资源
 */
public class ThreadDemo02 {

    public static void main(String[] args) {
        Dog dog1 = new Dog();
        Thread t1 = new Thread(dog1);
        t1.start();
    }
}

class Dog implements Runnable {

    int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println(Thread.currentThread().getName() + ": 小狗汪汪叫 " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            if (count == 8) {
                break;
            }
        }
    }
}
